package com.dingreading.cloud.web.service.impl;

import com.dingreading.cloud.web.dto.ReadInterestQuestionDto;
import com.dingreading.cloud.web.entity.ReadInterestQuestion;
import com.dingreading.cloud.web.entity.table.ReadInterestQuestionTableDef;
import com.dingreading.cloud.web.mapper.ReadInterestQuestionMapper;
import com.dingreading.cloud.web.service.ReadInterestQuestionService;
import com.mybatisflex.core.query.QueryCondition;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 *  服务层实现。
 *
 * @author Administrator
 * @since 2024-09-11
 */
@Service
public class ReadInterestQuestionServiceImpl extends BaseServiceImpl<ReadInterestQuestionMapper, ReadInterestQuestion, ReadInterestQuestionTableDef> implements ReadInterestQuestionService {

    @Override
    protected ReadInterestQuestionTableDef getTable() {
        return ReadInterestQuestionTableDef.readInterestQuestion;
    }

    @Resource
    protected ReadInterestQuestionMapper readInterestQuestionMapper;

    @Override
    public List<ReadInterestQuestionDto> dtoListByIds(List<Long> ids) {
        QueryWrapper wrapper = QueryWrapper.create()
                .where(table.id.in(ids))
                .orderBy(table.emphasisType.asc(), table.stage.asc(), table.emphasisChildType.asc());
        return getMapper().selectListByQueryAs(wrapper, ReadInterestQuestionDto.class);
    }

    @Override
    public List<String> randomNumberAndIds(Integer stage) {
        return readInterestQuestionMapper.randomNumberAndIds(stage);
    }

    @Override
    public List<ReadInterestQuestionDto> getInterestQuestionList() {
        QueryCondition condition = QueryCondition.createEmpty();
        condition.and(table.enabled.eq(1))
                .and(table.emphasisType.eq(4));

        QueryWrapper wrapper = QueryWrapper.create()
                .where(condition)
                .orderBy(table.id.asc());
        return getMapper().selectListByQueryAs(wrapper, ReadInterestQuestionDto.class);
    }

}
